package generator.util;

import generator.meta.ClassMeta;

import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 * User: sunguangzhu
 * Date: 13-8-10
 * Time: 下午8:57
 * To change this template use File | Settings | File Templates.
 */
public class JsUIUtils {
    public static String getFormUI(Field field, String fieldPackageName) {
        String formUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {

        } else if (fieldTypeName.contains("Integer")) {
            formUI = "$('#' + obj[myKey] + '" + field.getName() + "').numberbox({\n" +
                    "        min: 0,\n" +
                    "        required: true,\n" +
                    "        precision: 0,\n" +
                    "        max: 100\n" +
                    "    })";
        } else if (fieldTypeName.contains("Long")) {
            formUI = "$('#' + obj[myKey] + '" + field.getName() + "').numberbox({\n" +
                    "        min: 0,\n" +
                    "        required: true,\n" +
                    "        precision: 0,\n" +
                    "        max: 100\n" +
                    "    })";
        } else if (fieldTypeName.contains("Boolean")) {

        } else if (fieldTypeName.contains("Float")) {
            formUI = "$('#' + obj[myKey] + '" + field.getName() + "').numberbox({\n" +
                    "        min: 0,\n" +
                    "        required: true,\n" +
                    "        precision: 2,\n" +
                    "        max: 250\n" +
                    "    })";
        } else if (fieldTypeName.contains("Double")) {
            formUI = "$('#' + obj[myKey] + '" + field.getName() + "').numberbox({\n" +
                    "        min: 0,\n" +
                    "        required: true,\n" +
                    "        precision: 2,\n" +
                    "        max: 250\n" +
                    "    })";
        } else if (fieldTypeName.contains("Date")) {
            formUI = "$('#' + obj[myKey] + '" + field.getName() + "').datetimebox({\n" +
                    "        required: true,\n" +
                    "        formatter: formaterDateTime\n" +
                    "    })";
        } else if (fieldTypeName.contains("Set")) {

        } else {
            formUI = "$('#' + obj[myKey] + '" + field.getName() + "').combobox({\n" +
                    "        url: 'context/getKeyValueDtos.do',\n" +
                    "        valueField: 'id',\n" +
                    "        textField: 'text',\n" +
                    "        onBeforeLoad: function (param) {\n" +
                    "            param.className = '" + fieldPackageName.trim() + "';\n" +
                    "        }\n" +
                    "    })";
        }
        return formUI;
    }

    public static String getColumnUI(Field field, String comment, ClassMeta classMeta) {
        String cloumnUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Integer")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Long")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Boolean")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Float")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Double")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Date")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else if (fieldTypeName.contains("Set")) {
            cloumnUI = " {field: \"" + field.getName() + "\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        } else {
            cloumnUI = " {field: \"" + field.getName() + ".name\", title: \"" + comment + "\", width: fillsize(1 / " + (classMeta.getFieldSize()+1) + ")}";
        }
        return cloumnUI;
    }

    public static String getSimpleSearchUI(Field field, String comment, ClassMeta classMeta) {
        String simpleSearchUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Integer")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Long")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Boolean")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Float")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Double")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Date")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else if (fieldTypeName.contains("Set")) {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        } else {
            simpleSearchUI = "<div data-options=\"name:'" + field.getName() + "'\">" + comment + "</div>";
        }
        return simpleSearchUI;
    }

    public static String getAdvanceSearchUI(Field field, String comment, ClassMeta classMeta) {
        String advanceSearchUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Integer")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Long")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Boolean")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Float")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Double")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Date")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else if (fieldTypeName.contains("Set")) {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        } else {
            advanceSearchUI = "<td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td>";
        }
        return advanceSearchUI;
    }

    public static String getInputSearchUI(Field field, String comment, ClassMeta classMeta) {
        String inputUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Integer")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Long")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Boolean")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Float")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Double")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Date")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Set")) {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        }
        return inputUI;
    }

    public static String getViewSearchUI(Field field, String comment, ClassMeta classMeta) {
        String viewUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Integer")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Long")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Boolean")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Float")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Double")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Date")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else if (fieldTypeName.contains("Set")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        } else {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}"+field.getName()+"\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean."+field.getName()+"}\"></td></tr>";
        }
        return viewUI;
    }

    public static String getMenuUI(ClassMeta classMeta,String comment) {
        String menuUI = "<div><a href=\"#\" onclick=\"addTab('"+comment+"','"+classMeta.getLowerClassName()+"/index.do')\">"+comment+"</a></div>";
        return menuUI;
    }
}
